package com.heima.freemarker.controller;

import com.heima.freemarker.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class HelloController {

    @GetMapping("/helloFree")
    public String hello (Model model){
        //赋值给name
        model.addAttribute("name" , "freemaker-test") ;

        //构建student
        Student student = new Student() ;
        student.setName("浮生未歇");
        student.setAge(21);

        model.addAttribute("stu" , student) ;

        return "01-basic" ;
    }

    @GetMapping("/lm")
    public String lm(Model model){

        Student student = new Student() ;
        student.setName("浮生未歇");
        student.setAge(21);
        student.setMoney(152.1f);

        Student student2 = new Student() ;
        student2.setName("故梦");
        student2.setAge(21);
        student2.setMoney(152.1f);

        List<Student> list = new ArrayList<>() ;
        list.add(student);
        list.add(student2);

        model.addAttribute("ls" , list) ;

        Map<String , Student> map = new HashMap() ;
        map.put("stu1" , student);
        map.put("stu2" , student2);

        model.addAttribute("ms" , map) ;

        return "02-list";
    }
}
